﻿namespace HuwmanCode.ServiceProcess

open System
open System.Diagnostics
open System.ServiceProcess

///<summary>
/// Specifies that the WindowsService should be started after installation
///</summary>
[<AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)>]
type public StartAfterInstallAttribute(perform : bool) =
    inherit Attribute()
    new () = StartAfterInstallAttribute(true)
    
    member internal x.Perform
        with get() = perform

    static member IsDecorated(instance) =
        instance.GetType().GetCustomAttributes(typeof<StartAfterInstallAttribute>, true)
        |> Array.map(fun o -> o :?> StartAfterInstallAttribute)
        |> Array.tryFind(fun a -> a.Perform)
        |> Option.isSome
